{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 生成六个班的考试成绩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1=np.random.randint(0,100,size=(50,3))\n",
    "c2=np.random.randint(0,100,size=(50,3))\n",
    "c3=np.random.randint(0,100,size=(50,3))\n",
    "c4=np.random.randint(0,100,size=(50,3))\n",
    "c5=np.random.randint(0,100,size=(50,3))\n",
    "c6=np.random.randint(0,100,size=(50,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数组处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 合并各班级成绩\n",
    "score=np.vstack((c1,c2,c3,c4,c5,c6))\n",
    "# 生成性别数组\n",
    "sex=np.array(random.choices([0,1],k=300)).reshape(300,-1)\n",
    "# 合并性别与成绩\n",
    "data=np.concatenate((score,sex),axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 男生各科成绩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 各科最小值\n",
    "cond=data[:,3]==1\n",
    "np.min(data[:,:3][cond],axis=0)\n",
    "# 各科最大值\n",
    "np.max(data[:,:3][cond],axis=0)\n",
    "# 各科平均值\n",
    "np.mean(data[:,:3][cond],axis=0)\n",
    "# 各科中位数\n",
    "np.median(data[:,:3][cond],axis=0)\n",
    "# 各科标准差\n",
    "np.std(data[:,:3][cond],axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 女生各科成绩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 各科最小值\n",
    "cond=data[:,3]==0\n",
    "np.min(data[:,:3][cond],axis=0)\n",
    "# 各科最大值\n",
    "np.max(data[:,:3][cond],axis=0)\n",
    "# 各科平均值\n",
    "np.mean(data[:,:3][cond],axis=0)\n",
    "# 各科中位数\n",
    "np.median(data[:,:3][cond],axis=0)\n",
    "# 各科标准差\n",
    "np.std(data[:,:3][cond],axis=0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "276px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
